//
//  BKUserChoosePhotosView.m
//  bestkeep
//
//  Created by windCould on 16/12/1.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKUserChoosePhotosView.h"
#import "BKMyCommon.h"
@interface BKUserChoosePhotosView ()

@property (nonatomic,strong)UIImageView * leftImgV;
@property (nonatomic,strong)UIImageView * rightImgV;
@property (nonatomic,strong)UILabel * tipLabel;

@property (nonatomic,strong)UIImageView * uploadTagLeftView;
@property (nonatomic,strong)UIImageView * uploadTagRightVeiw;


@end


@implementation BKUserChoosePhotosView


-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setUpViews];
        
    }
    
    return  self;
}

-(void)setLeftImg:(UIImage *)leftImg
{
    _leftImg = leftImg;
    [_leftImgV setImage:_leftImg];
    _uploadTagLeftView.hidden = NO;
}

-(void)setRightImg:(UIImage *)rightImg
{
    _rightImg = rightImg;
    [_rightImgV setImage:_rightImg];
    _uploadTagRightVeiw.hidden = NO;
}

#pragma mark =========================Function==================================

-(void)selectLeftImgV
{
    if ([self.myDelegate respondsToSelector:@selector(bkUserChoosePhotosView: clickLeftImgTag:)]) {
        
        [self.myDelegate bkUserChoosePhotosView:self clickLeftImgTag:1];
    }
}

-(void)selectRightImgV
{
    if ([self.myDelegate respondsToSelector:@selector(bkUserChoosePhotosView:clickRightImgTag:)]) {
        
        [self.myDelegate bkUserChoosePhotosView:self clickRightImgTag:2];
    }
}

#pragma mark =========================布局=======================================

-(void)setUpViews{
    
    
    _leftImgV = [[UIImageView alloc]initWithFrame:CGRectZero];
    _leftImgV.contentMode =  UIViewContentModeScaleToFill;
    _leftImgV.image = [UIImage imageNamed:@"BK_My_shangchuanzhengmian-"];
    _leftImgV.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapLeftImgV = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectLeftImgV)];
    [_leftImgV addGestureRecognizer:tapLeftImgV];
    [self addSubview:_leftImgV];
    
    _rightImgV = [[UIImageView alloc]initWithFrame:CGRectZero];
    _rightImgV.contentMode =  UIViewContentModeScaleToFill;
    _rightImgV.image = [UIImage imageNamed:@"BK_My_shangchuanfanmian-"];
    _rightImgV.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapRightImgV = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectRightImgV)];
    [_rightImgV addGestureRecognizer:tapRightImgV];
    
    _uploadTagLeftView = [[UIImageView alloc]init];
    _uploadTagLeftView.image = [UIImage imageNamed:@"BK_My_印章_"];
    _uploadTagLeftView.hidden = YES;
    [_leftImgV addSubview:_uploadTagLeftView];
    [self addSubview:_rightImgV];
    
    _uploadTagRightVeiw = [[UIImageView alloc]init];
    _uploadTagRightVeiw.image = [UIImage imageNamed:@"BK_My_印章_"];
    _uploadTagRightVeiw.hidden = YES;
    [_rightImgV addSubview:_uploadTagRightVeiw];
    
    _tipLabel = [UILabel new];
    _tipLabel.numberOfLines = 0;
    NSString *tipStr = @"温馨提示：请上传原始比例的身份证正反面，请勿裁剪涂改，保证身份信息清晰显示，否则无法通过审核。";
    NSMutableAttributedString *attrStrr = [[NSMutableAttributedString alloc] initWithString:tipStr];
    [attrStrr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0, 46)];
    [attrStrr addAttribute:NSForegroundColorAttributeName value:RGBCOLOR(0, 186, 156, 1) range:NSMakeRange(0, 5)];
    [attrStrr addAttribute:NSForegroundColorAttributeName value:RGBCOLOR(178, 178, 178, 1)range:NSMakeRange(5, 42)];
    _tipLabel.attributedText = attrStrr;
    [self addSubview:_tipLabel];
    
    [self layoutViews];
}

-(void)layoutViews{
    
    
    [_leftImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.mas_top).offset(20);
        make.left.mas_equalTo(self.mas_left).offset(ApplicationBackGauge);
        make.size.mas_equalTo(CGSizeMake((SCREENWIDTH-6-ApplicationBackGauge*2)/2, 115));
    }];
    
    [_rightImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.mas_top).offset(20);
        make.left.mas_equalTo(_leftImgV.mas_right).offset(6);
        make.size.mas_equalTo(CGSizeMake((SCREENWIDTH-6-ApplicationBackGauge*2)/2, 115));
    }];
    
    [_tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(_leftImgV.mas_bottom).offset(10);
        make.left.mas_equalTo(self.mas_left).offset(ApplicationBackGauge);
        make.right.mas_equalTo(_rightImgV.mas_right).offset(0);
    }];

    CGFloat width = (SCREENWIDTH-6-ApplicationBackGauge*2)/2;
    CGFloat hight = 115;
    
    [_uploadTagLeftView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(_leftImgV.mas_bottom).offset(-5);
        make.right.mas_equalTo(_leftImgV.mas_right).offset(-5);
        make.width.mas_offset(width/173*90);
        make.height.mas_offset(hight/150*45);
    }];
    
    [_uploadTagRightVeiw mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(_rightImgV.mas_bottom).offset(-5);
        make.right.mas_equalTo(_rightImgV.mas_right).offset(-5);
        make.width.mas_offset(width/173*90);
        make.height.mas_offset(hight/150*45);
    }];

}


@end
